/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.playground.core.entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 *
 * @author Tiago Peres
 */
@Entity
@Table(uniqueConstraints = {@UniqueConstraint(columnNames={"gameTitle_id", "player_id"})})
public class Score implements Serializable {
    @Id
    @GeneratedValue
    private long id;
    
    private int losses;
    private int playedTimes;
    private int points;
    private int victories;
    
    // relationships
    @ManyToOne(optional = false)
    @JoinColumn(name="gameTitle_id")
    private GameTitle gameTitle;
    
    @ManyToOne(optional = false)
    @JoinColumn(name="player_id")
    private Player player;

    public GameTitle getGameTitle() {
        return gameTitle;
    }

    public void setGameTitle(GameTitle gameTitle) {
        this.gameTitle = gameTitle;
    }

    public int getLosses() {
        return losses;
    }

    public void setLosses(int losses) {
        this.losses = losses;
    }

    public int getPlayedTimes() {
        return playedTimes;
    }

    public void setPlayedTimes(int playedTimes) {
        this.playedTimes = playedTimes;
    }

    public int getPoints() {
        return points;
    }

    public void setPoints(int points) {
        this.points = points;
    }

    public int getVictories() {
        return victories;
    }

    public void setVictories(int victories) {
        this.victories = victories;
    }

    public long getId() {
        return id;
    }

    public Player getPlayer() {
        return player;
    }

    public void setPlayer(Player player) {
        this.player = player;
    }
    
    @Override
    public boolean equals(Object o){
        if (o.getClass().equals(getClass())){
            return ((Score) o).getId() == getId();
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 59 * hash + (int) (this.id ^ (this.id >>> 32));
        return hash;
    }
}
